<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../img/asset-favico.ico">
        <title>登录</title>
        <link rel="stylesheet" href="../css/page-health-login.css" />
        <link rel="stylesheet" href="../plugins/elementui/index.css" />
        <script src="../plugins/jquery/dist/jquery.min.js"></script>
        <script src="../plugins/healthmobile.js"></script>
        <script src="../plugins/vue/vue.js"></script>
        <script src="../plugins/vue/axios-0.18.0.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
        <script>var num = 0</script>
    </head>
    <body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div class="app" id="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left"><i class="icon-back"></i></span>
            <span class="center">传智健康</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <div style="margin-left: 20px">手机快速登录</div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="login">
                <form id='login-form'>
                    <div class="input-row">
                        <label>手机号</label>
                        <div class="loginInput">
                            <input v-model="loginInfo.telephone" id='account' type="text" placeholder="请输入手机号">
                            <input id="validateCodeButton" @click="sendValidateCode()" type="button" style="font-size: 12px" value="获取验证码">
                        </div>
                    </div>
                    <div class="input-row">
                        <label>验证码</label>
                        <div class="loginInput">
                            <input v-model="loginInfo.validateCode" style="width:80%" id='password' type="password" placeholder="请输入验证码">
                        </div>
                    </div>
                    <div class="input-row" style="font-size: 12px">
                        <input type="checkbox" checked>
                        阅读并同意《传智健康用户协议》《传智健康隐私条款》
                    </div>
                    <a @click="login()" href="#"  >
                    <div class="btn yes-btn" >
                        登录
                    </div>
                    </a>
                    <span id="btnSend" class="fasong"></span>
                </form>
            </div>
        </div>
    </div>
    </body>
    <script>
        var vue = new Vue({
            el:'#app',
            data:{
                loginInfo:{},//登录信息
            },
            methods: {
                //发送验证码
                sendValidateCode() {
                    var telephone = this.loginInfo.telephone;
                    if (!checkTelephone(telephone)) {
                        this.$message.error('请输入正确的手机号');
                        return false;
                    }
                    validateCodeButton = $("#validateCodeButton")[0];

                    clock = window.setInterval(doLoop, 1000); //一秒执行一次
                    axios.post("/validateCode/send4Login.do?telephone=" + telephone).then((response) => {
                        if (!response.data.flag) {
                            //验证码发送失败
                            this.$message.error('验证码发送失败，请检查手机号输入是否正确');
                        }
                    });
                },
                //登录
                login() {
                    var telephone = this.loginInfo.telephone;
                    if (!checkTelephone(telephone)) {
                        this.$message.error('请输入正确的手机号');
                        return false;
                    }
                    axios.post("/member/login.do", this.loginInfo).then((response) => {
                        if (response.data.flag) {
                            //登录成功,跳转到index.html
                            window.location.href = "/pages/index.html";
                        } else {
                            //失败，提示失败信息
                            if (response.data.data < 3) {
                                this.$message.error("您还有" + (3 - response.data.data) + "次机会");
                                response.data.data = response.data.data + 1
                            } else {
                                this.$message.error("您已经没有机会了,账号已被锁定");
                                $(function () {
                                        LockButton('#btnSend', 60);
                                    //读取cookie
                                    if ($.cookie("djsendtime") != undefined && !isNaN($.cookie("djsendtime"))) {  //读取到了cookie值
                                        var djsendtime = $.cookie("djsendtime");
                                        var now = new Date().getTime();  //当前时间戳
                                        var locksecends = parseInt((djsendtime - now) / 1000);
                                        if (locksecends <= 0) {
                                            $.cookie("djsendtime", null);
                                        } else {
                                            LockButton('#btnSend', locksecends);
                                        }
                                    }
                                })

                                // 按钮倒计时
                                var LockButton = function (btnObjId, locksecends) {
                                    //1.获取当前系统时间
                                    //2.获取 locksecends 后的系统时间
                                    //3.用cookie保存到期时间
                                    //4.每次加载后获取cookie中保存的时间
                                    //5.用到期时间减去当前时间获取倒计时
                                    var djsendtime = $.cookie("djsendtime");
                                    if (djsendtime == null || djsendtime == undefined || djsendtime == 'undefined' || djsendtime == 'null') {
                                        var now = new Date().getTime();  //当前时间戳
                                        var endtime = locksecends * 1000 + now;  //结束时间戳
                                        $.cookie("djsendtime", endtime);  //将结束时间保存到cookie
                                    }
                                    $(btnObjId).addClass('disabled').attr('disabled', 'disabled').text('您的账号已被锁定,请过(' + locksecends + ')秒后重试');
                                    $('body').off('click', '#btnSendSMS');
                                    var timer = setInterval(function () {
                                        locksecends--;
                                        $(btnObjId).text('您的账号已被锁定,请过(' + locksecends + ')秒后重试');
                                        if (locksecends <= 0) {
                                            //倒计时结束清除cookie值
                                            $.cookie("djsendtime", null);
                                            $(btnObjId).removeClass('disabled').removeAttr('disabled').text('');
                                            $('body').on('click', btnObjId);
                                            clearInterval(timer);
                                        }
                                    }, 1000);
                                };
                            }
                        }
                    });
                },
            }
        });
    </script>
</html>